package by.exposit.service;

import by.exposit.dao.FieldDAO;
import by.exposit.dao.entity.FieldEntity;
import by.exposit.domain.Field;
import org.dozer.DozerBeanMapperSingletonWrapper;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
@Service
@Transactional
public class FieldServiceImpl implements FieldService {
    @Autowired
    private FieldDAO fieldDAO;


    @Override
    public List<Field> fieldList() {
        Mapper mapper = DozerBeanMapperSingletonWrapper.getInstance();
        List<Field> field =   new ArrayList<Field>();
        List<FieldEntity> sphereEntities = fieldDAO.getAll();
            for(FieldEntity fieldEntity : sphereEntities )
            {
                field.add(mapper.map(fieldEntity,Field.class));
            }

        return field;

    }



    @Override
    public Field retrieveField(long fieldId)
    {
        Mapper mapper = DozerBeanMapperSingletonWrapper.getInstance();
        return mapper.map( fieldDAO.retrieveSphere(fieldId), Field.class);
    }
}
